package controller.environment.ground;

import java.awt.Color;
import java.util.Random;

import controller.environment.GroundManager;

import reference.constants.ConstantProblem;

public class GroundFertile extends Ground {

	private Random m_random;
	
	public GroundFertile(GroundManager ground_manager, int pos_x, int pos_y){
		super(ground_manager, pos_x, pos_y);
		m_random = new Random();
	}
	
	/**
	 * Randomly seeds the ground
	 * <br/><strong>Attention: </strong>Can return a <strong>null</strong> value
	 * @return a new Ground square if a seed was placed
	 */
	private Ground randomSeeding(){
		if(m_random.nextDouble()<ConstantProblem.PROBABILITY_OF_SEEDING){
			return new GroundSeeded(m_groundManager, m_posX, m_posY);
		}
		return null;
	}

	public void actsParticular() {
		Ground newGround = randomSeeding();
		if(newGround!=null){
			m_groundManager.setNewGround(newGround, m_posX, m_posY);
		}
	}

	public Color getColor() {
		return new Color(91, 59, 17);
	}

	public void evolve() {
		Ground newGround = new GroundSeeded(m_groundManager, m_posX, m_posY);
		m_groundManager.setNewGround(newGround, m_posX, m_posY);
	}
}
